home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 1 / QRZ Ham Radio Callsign Database - December 1993.iso / ucsd / packet / tcpip / amiga / asrc29k.lha / icmpdump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-08  |  1.4 KB  |  66 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "internet.h"
  5. #include "icmp.h"
  6. #include "trace.h"
  7. #include "ip.h"
  8.  
  9. /* Dump an ICMP header */
  10. void
  11. icmp_dump(fp,bpp,source,dest,check)
  12. FILE *fp;
  13. struct mbuf **bpp;
  14. int32 source,dest;
  15. int check;        /* If 0, bypass checksum verify */
  16. {
  17.     struct icmp icmp;
  18.     int16 csum;
  19.  
  20.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  21.         return;
  22.     csum = cksum(NULLHEADER,*bpp,len_p(*bpp));
  23.     
  24.     ntohicmp(&icmp,bpp);
  25.     
  26.     fprintf(fp,"ICMP: type %s",smsg(Icmptypes,ICMP_TYPES,uchar(icmp.type)));
  27.  
  28.     switch(uchar(icmp.type)){
  29.     case ICMP_DEST_UNREACH:
  30.         fprintf(fp," code %s",smsg(Unreach,NUNREACH,uchar(icmp.code)));
  31.         break;
  32.     case ICMP_REDIRECT:
  33.         fprintf(fp," code %s",smsg(Redirect,NREDIRECT,uchar(icmp.code)));
  34.         break;
  35.     case ICMP_TIME_EXCEED:
  36.         fprintf(fp," code %s",smsg(Exceed,NEXCEED,uchar(icmp.code)));
  37.         break;
  38.     case ICMP_PARAM_PROB:
  39.         fprintf(fp," pointer %u",icmp.args.pointer);
  40.         break;
  41.     case ICMP_ECHO:
  42.     case ICMP_ECHO_REPLY:
  43.     case ICMP_INFO_RQST:
  44.     case ICMP_INFO_REPLY:
  45.     case ICMP_TIMESTAMP:
  46.     case ICMP_TIME_REPLY:
  47.         fprintf(fp," id %u seq %u",icmp.args.echo.id,icmp.args.echo.seq);
  48.         break;
  49.     }
  50.     if(check && csum != 0){
  51.         fprintf(fp," CHECKSUM ERROR (%u)",csum);
  52.     }
  53.     fputc('\n',fp);
  54.     /* Dump the offending IP header, if any */
  55.     switch(icmp.type){
  56.     case ICMP_DEST_UNREACH:
  57.     case ICMP_TIME_EXCEED:
  58.     case ICMP_PARAM_PROB:
  59.     case ICMP_QUENCH:
  60.     case ICMP_REDIRECT:
  61.         fprintf(fp,"Returned ");
  62.         ip_dump(fp,bpp,0);
  63.     }
  64. }
  65.  
  66.